package com.ocom.payconfig.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.ocom.common.entity.card.EntityKitchenPrtInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.common.request.payconfig.KitchenPrinter.dto.KitchenPrtListDto;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payconfig.dao.IDaoKitchenPrtInfo;
import com.ocom.payconfig.service.KitchenPrtInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class KitchenPrtInfoServiceImpl extends ServiceImpl<IDaoKitchenPrtInfo, EntityKitchenPrtInfo> implements KitchenPrtInfoService {

    @Autowired
    private IDaoKitchenPrtInfo iDaoKitchenPrtInfo;


    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.SLAVE)
    public List<KitchenPrtListDto> kitchenPrtList(Long comId, Long restId, Long prtId, int page, int size) {
        PageHelper.startPage(page, size);
        return iDaoKitchenPrtInfo.kitchenPrtList(comId, restId, prtId);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    public boolean updateKitchenInfoPrt(Long comId, String prtSn, String prtName, String prtPhone) {
        UpdateWrapper<EntityKitchenPrtInfo> updateWrapper = Wrappers.update();
        updateWrapper.eq("com_id", comId);
        updateWrapper.eq("prt_sn", prtSn);

        updateWrapper.set("prt_name", prtName);
        updateWrapper.set("prt_phone", prtPhone);
        return this.update(updateWrapper);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "comId",isMaster = MasterSlaveEnum.MASTER)
    public boolean saveKitchenInfoPrt(Long comId, EntityKitchenPrtInfo entityKitchenPrtInfo) {
        return this.saveOrUpdate(entityKitchenPrtInfo);
    }

    @Override
    @DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.SLAVE)
    public List<KitchenPrtListDto> kitchenPrtList(Long companyId,Integer product) {
        return iDaoKitchenPrtInfo.kitchenPrtList2(product);
    }


}
